<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
<link rel="stylesheet" href="../../lib/layui/css/layui.css" media="all">
    <style>
        .form-wrap{
            padding: 10px;
        }
    </style>
</head>
<body>
<div class="form-wrap">
    <!-- 新增商品分类表单 -->
    <form id="effect_form" class="layui-form" method="post" enctype="multipart/form-data">
        <div class="layui-form-item">
            <label class="layui-form-label">分类名称</label>
            <div class="layui-input-block">
                <input id="effect_name_input" name="effectName" type="text" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序码</label>
            <div class="layui-input-block">
                <input id="effect_sortcode_input" type="text" name="sortCode"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
           <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <select id="effect_status_select" name="status">
						<option value="1">正常</option>
						<option value="0">禁用</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block"> 
                <button class="layui-btn" type="button" onclick="effectForm.submit()">提交</button>
            </div>
        </div>
    </form>
</div>
	<script src="../../publicjs/jquery-1.8.0.min.js"></script>
	<script src="../../publicjs/smallkingutil.js"></script>
	<script src="../../lib/layui/layui.js"></script>
<script type="text/javascript">
layui.use(['form', 'laydate'], function(){
    var form = layui.form,
    	layer = layui.layer;
	// 用户表单相关的操作对象
	window.effectForm = {
		submit : function() {
			var effectName = $("#effect_name_input").val();
			var sortCode = $("#effect_sortcode_input").val();
			var status = $("#effect_status_select").val();
			var data = {
				effectName : effectName,
				sortCode : sortCode,
				status : status
			}
			var url, msg;
			if(this.effectId){
				url = commonUtil.domain() +"/admin/mall/effect/update";
				msg = "修改";
				data.effectId = this.effectId;
			}else{
				url = commonUtil.domain() +"/admin/mall/effect/insert";
				msg = "新增";
			}
			var ajaxParam = {
				url : url,
				
				data : data
			}
			console.info(ajaxParam);
			ajaxUtil.post(ajaxParam, function(data){
				if (data.code == 200) {
					// 关闭当前的表单弹窗 刷新父级页面的数据表格
					var parentHtml = window.parent;
					parentHtml.layer.closeAll();
					parentHtml.effectTable.refresh();
				} else {
					layer.msg(msg + "失败，请联系开发人员。");
				}
			})
		}
	}
	
	var effectId = commonUtil.getRequestParam("effectId");
	if (effectId){
		effectForm.effectId = effectId;
		// 请求后台得到当前修改的用户数据，将其显示在表单里
		var ajaxParam = {
			url : commonUtil.domain() +'/admin/mall/effect/detail',
			data : {
				effectId : effectId
			}
		}
		ajaxUtil.post(ajaxParam, function(data) {
			formUtil.setForm($('#effect_form'), data.data);
			form.render("select");
		});
	}
	
});
</script>
<script>
	$(function(){
				commonUtil.setMaxLength(40);
			})
</script>
</body>
